package br.com.odontosul.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.odontosul.connection.Conexao;
import br.com.odontosul.entity.Atendimento;

public class AtendimentoDAO {
	
	private Connection connection;  
	
	public AtendimentoDAO() throws SQLException{  
        this.connection = Conexao.getConnectionFactory();  
    }  
	
	public List<Atendimento> recuperaTodosAtendimentos() throws SQLException {  
        
        PreparedStatement stmt = this.connection.prepareStatement("SELECT c.*, a.*, p.nome AS nomePaciente FROM paciente p, consulta c, atendimento a where c.id_paciente = p.id  and a.id_consulta = c.id");  
        ResultSet rs = stmt.executeQuery();  
        List<Atendimento> list = new ArrayList<Atendimento>();  
          
        while (rs.next()){  
        	Atendimento atendimento = new Atendimento();  
        	atendimento.setId(rs.getLong("id"));
        	/*atendimento.setObservacoes(rs.getString("obs_consulta"));
        	atendimento.setNomePaciente(rs.getString("nomePaciente"));
        	atendimento.setDataConsulta(rs.getDate("dt_consulta"));*/ 

           list.add(atendimento);  
        }  
          
        rs.close();  
        stmt.close();  
        return list;     
     }

}
